package com.hanhy.util;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.os.WindowsUtils;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by Administrator on 2016/12/23.
 *   private static Properties p = null;
 *   private static String config = System.getProperty("user.dir")+"/config.properties";
 *   private static String OSType = System.getProperty("os.name");
 * config.properties文件保存的操作系统的信息：1、Mac系统  2、windows系统  两种操作系统下，浏览器的安装位置不一样
 * 分两步走：
 * 1、先实现简单的firefox浏览器测试，并且不添加代理和其它firefox插件
 * 2、实现多浏览器同时测试
 *
 */
public class DriverFactory {
    private static String firefoxdriver;
    static Log log = new Log(DriverFactory.class);

    public static WebDriver getFirefoxDriver(){
        WebDriver driver = null;

//        try {
////            WindowsUtils.tryToKillByName("firefox");
//        } catch (Exception e) {
//            log.error("not find firefox process");
//        }
        FirefoxProfile profile = new FirefoxProfile();
        firefoxdriver = "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
        log.info("webdriver.firefox.bin path is:"+firefoxdriver);
        System.setProperty("webdriver.firefox.bin",firefoxdriver);
        driver = new FirefoxDriver(profile);
        return driver;
    }

}
